#include"process.h"
#include<unistd.h>
#include<time.h>
//double speed = 1.0;
double cur = 0.0;
double start = 1.0;//最低网速
//函数指针类型
typedef void(*callback)(double,double);
//模拟网速波动
double speedrand(double start,double range)
{
 int int_range = (int)range;
 return start + rand() % int_range + (range - int_range);
}
void DownLoad(double total,callback cb)
{
while(1)
{
//处理越界行为
if(cur > total)
{
  cur = total;
cb(total,cur);
break;
}
cb(total,cur);//更新进度，按照当前的下载进度来刷新进度条
cur += speedrand(start,20.3);
usleep(3000);
}
}
int main()
{
srand(time(NULL));
printf("下载数据量为%d的文件\n",10000);
DownLoad(10000,FlushProcess);
printf("下载数据量为%d的文件\n",80000);
DownLoad(80000,FlushProcess);
//verson1
//Process();
return 0;
}


